#!/usr/bin/env python
import pygtk
pygtk.require('2.0')

import gtk
import gnome
import gnome.ui
import gconf
import gettext
_ = gettext.gettext

from gnometwitter import twitter_poster
from gnometwitter import twitter_prefs
from gnometwitter import gnome_twitter_globals

#FIXME: need to get this path from auto*
gettext.bindtextdomain('gnome-twitter', gnome_twitter_globals.localedir)
gettext.textdomain('gnome-twitter')
    
gtk.window_set_default_icon_name('gnome-twitter')
        
class TwitterApp:
    def __init__(self):
        self.prefs_key = "/apps/gnome-twitter"

        client = gconf.client_get_default()
        value = client.get_bool(self.prefs_key + "/initialized")

        accel_group = gtk.AccelGroup()

        poster = twitter_poster.BlogPoster(prefs_key=self.prefs_key,
                                        accel_group=accel_group,
                                        on_entry_posted=self._onEntryPosted)

        if (value == None or value == False):
            poster._showPrefDialog()
            client.set_bool(self.prefs_key + "/initialized", True)
        
        poster_window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        poster_window.set_title(_("Post Blog Entry"))
        poster_window.connect('destroy', lambda w: gtk.main_quit())
        poster_window.add_accel_group(accel_group)

        poster_window.add(poster)
        poster_window.show_all()

    def _onEntryPosted(self):
        gtk.main_quit()
        
app = TwitterApp()
gtk.main()
